<template>
    <IContent v-model="componentProps">

        <ISearch v-model="search">
            <Row>
                <FormItem label="入库状态">
                    <RemoteButton size="small" url="common/select/dictionaries/ENTRYORDER_STATUS"
                                  v-model="search.status"></RemoteButton>
                </FormItem>
            </Row>
            <FormItem label="入库单号">
                <Input v-model="search.name" placeholder="入库单号" size="small"></Input>
            </FormItem>
            <FormItem :label-width="1">
                <ButtonGroup>
                    <Button type="primary" icon="ios-search" size="small" @click="getLists">搜索</Button>
                    <Button type="success" icon="ios-add" size="small" @click="openComponent(`ICreate`)">添加</Button>
                </ButtonGroup>
            </FormItem>
        </ISearch>

        <ITable :current="page.current" :table="table" :total="page.total" @on-page-change="pageChange"
                :loading="loading">
            <template slot-scope="{row, index}" slot="status">
                <RemoteSpan url="common/select/dictionaries/ENTRYORDER_STATUS" v-model="row.status"></RemoteSpan>
            </template>
            <template slot-scope="{ row, index }" slot="action">
                <ButtonGroup>
                    <Button type="warning" size="small" v-if="row.status === '0'"
                            @click="openComponent('IUpdate', {id: row.id})">编辑
                    </Button>
                    <Button type="warning" size="small" v-if="row.status === '0'"
                            @click="submitForAffirm(row.id)">确认
                    </Button>
                </ButtonGroup>
            </template>
        </ITable>

        <component slot="component" v-if="componentProps.value" :is="componentProps.view" v-model="componentProps.value"
                   :props="componentProps.props"
                   @input="getLists(page.current)"></component>
    </IContent>
</template>

<script>
    import IContent from "../../../../components/layout/IContent";
    import ISearch from "../../../../components/layout/ISearch";
    import ITable from "../../../../components/layout/ITable";
    import IContentMixins from "../../../../mixins/iContentMixins"
    import RemoteSpan from "../../../../components/layout/RemoteSpan";
    import RemoteButton from "../../../../components/form/remoteButton";

    export default {
        components: {
            RemoteButton,
            RemoteSpan,
            ICreate: () => import('./create'),
            IUpdate: () => import('./update'),
            ITable, ISearch, IContent
        },
        mixins: [IContentMixins],
        data() {
            return {
                search: {},
                table: {
                    columns: [
                        {
                            title: '入库仓单号',
                            key: 'code'
                        },
                        {
                            title: '客户入库单号',
                            key: 'foreign'
                        },
                        {
                            title: '预计到货日期',
                            key: 'expect_at'
                        },
                        {
                            title: '状态',
                            slot: 'status'
                        },
                        {
                            title: '操作',
                            slot: 'action'
                        }
                    ]
                }
            }
        },
        methods: {
            getLists(page) {
                this._lists(`entryorder/index`, page);
            },
            submitForAffirm(id){
                this._confirm().then(() => {
                    this.loading = true;
                    this.$http.put(`entryorder/index/${id}/affirm`).then(() => {
                        this.$Message.success('确认成功');
                        this.getLists();
                    }).finally(() => {
                        this.loading = false;
                    })
                });
            },
        }
    }
</script>

<style>
</style>
